/**
 * name:xue
 * @:生产环境
 */
const path = require('path');
const {merge} = require('webpack-merge'); //引入合并插件
const common = require('../webpack.commons.js');
//const HtmlCriticalWebpackPlugin = require('html-critical-webpack-plugin'); // 集成critical的html-webpack-plugin版本
const  { CleanWebpackPlugin }  =  require ( 'clean-webpack-plugin' ) ;//清理dist文件夹
//首屏加载
const HtmlCriticalWebpackPlugin = require('html-critical-webpack-plugin'); // 集成critical的html-webpack-plugin版本


module.exports = merge(common,{//将common合并到当前文件
    mode:'production',
    module:{
        rules: [
            //生产环境下压缩图片
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                use:['image-webpack-loader']
            }
        ],
    },
    plugins:[
        //首屏加载
        new HtmlCriticalWebpackPlugin({
            base: path.resolve(__dirname, '../dist'),
            src: 'index.html',
            dest: 'index.html',
            inline: true,
            minify: true,
            extract: true,
            width: 375,
            height: 565,
            // 确保调用打包后的JS文件
            penthouse: {
                blockJSRequests: false
            }
        }),
        //清理dist文件夹
        new CleanWebpackPlugin({
            root:path.resolve(__dirname,'..'),
            verbose:true,//打印日志
            cleanOnceBeforeBuildPatterns:["*/sprite.*.*"]//要删除的文件以及跳过的文件，！为跳过
        }),

    ]
})